package com.heather.exam.controller.admincontroller;

import com.heather.exam.mapper.admin.StudentMapper;
import com.heather.exam.models.certificate.Student;
import com.heather.exam.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/{id}/applyCertificate")
    public ResponseEntity<String>applyCertificate(@PathVariable int id) {
        int passingScore = 60; // 设置及格分数

        String result = studentService.applyCertificate(id, passingScore);

        if (result.contains("恭喜")) {
            return ResponseEntity.ok(result);
        } else {
            return ResponseEntity.badRequest().body(result);
        }
    }

//        @Autowired
//        private StudentMapper studentMapper;
//
//        @GetMapping("/students/{id}/applyCertificate")
//        public ResponseEntity<String> applyCertificate(@PathVariable int id) {
//            Student student = studentMapper.getStudentById(id);
//
//            if (student == null) {
//                return ResponseEntity.badRequest().body("Student not found");
//            }
//
//            if (student.getScore() >= 90) {//90为及格分数，可调整
//                studentMapper.updateCertificateStatus(id, true);
//                return ResponseEntity.ok("Congratulations! You have been awarded the Outstanding Student certificate.");
//            } else {
//                return ResponseEntity.ok("Your score does not meet the minimum requirement for the certificate.");
//            }
//        }
    }


